<!doctype html>
<html>
	<head>
		<title>Shark Viewer</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		
			
		<script src="js/threejs/three.min.js"></script>
		<script src="js/threejs/TrackballControls.js"></script>
		<script src="./js/shark_viewer.js"></script>
		<!-- optional only if show_stats = true -->
		<script src="js/threejs/Stats.js"></script>
<script id="swc" type='text/plain'>
# ORIGINAL_SOURCE NeuronStudio 0.8.80
# CREATURE
# REGION
# FIELD/LAYER
# TYPE
# CONTRIBUTOR
# REFERENCE
# RAW
# EXTRAS
# SOMA_AREA
# SHINKAGE_CORRECTION 1.0 1.0 1.0
# VERSION_NUMBER 1.0
# VERSION_DATE 2007-07-24
# SCALE 1.0 1.0 1.0
 1 1 14.566132 34.873772 7.857000 0.717830 -1
 2 0 16.022520 33.760513 7.047000 0.463378 1
 3 5 17.542000 32.604973 6.885001 0.638007 2
 4 0 19.163984 32.022469 5.913000 0.602284 3
 5 0 20.448090 30.822802 4.860000 0.436025 4
 6 6 21.897903 28.881084 3.402000 0.471886 5
 7 0 18.461960 30.289471 8.586000 0.447463 3
 8 6 19.420759 28.730757 9.558000 0.496217 7
</script>
<script id='metadata_swc' type='text/plain'>
[{"label":"undefined","type":0},{"label":"soma","type":1},{"label":"axon","type":2},{"label":"dendrite","type":3},{"label":"apical dendrite","type":4},{"label":"fork point","type":5},{"label":"end point","type":6},{"label":"custom","type":7}]
</script>
</head>
<body>
	<label for='swc_input'>Upload a swc file to view it in the SharkViewer:</label><input type='file' name='swc_input' id='swc_input' />
	<!-- three.js container -->
    	<div id="container" style='position:relative'></div>
	<!-- info on screen display -->


	<script type='text/javascript'>
	var mdata;
	function readSwcFile(e) {
		var f = e.target.files[0]; 
		console.log(f);
		if (f) {
			var r = new FileReader();
			r.onload = function(e2) { 
				var swc_txt = e2.target.result;
				var swc = swc_parser(swc_txt);
				if ( Object.keys(swc).length > 0 ) {
					//remove previous neuron
					document.getElementById('container').innerHTML = "";

					var s = new SharkViewer({
						swc: swc, 
						dom_element: 'container', 
						center_node: -1, 
						show_stats: true, 
						metadata: mdata
					});
					s.init();
					s.animate();
				}
				else {
					alert("Please upload a valid swc file.");
				}
			}
			r.readAsText(f);
		} else { 
		      alert("Failed to load file");
		}
	}
	window.onload = function() {
		document.getElementById('swc_input').addEventListener('change', readSwcFile, false);
		var swc = swc_parser(document.getElementById("swc").text);
		mdata = JSON.parse(document.getElementById("metadata_swc").text);
		var s = new SharkViewer({
			swc: swc, 
			mode: 'particle',
			dom_element: 'container', 
			center_node: -1, 
			show_stats: true, 
			metadata: mdata});
		s.init();
		s.animate();
    window.s = s;
	}
	</script>
</body>
</html>

